package practica6;

import java.util.LinkedList;
import java.util.List;

import framework.IRule;

public class ReglaAv2 implements IRule<StateB> {

    @Override
    public List<StateB> apply(StateB state) {
	int y = state.posX();
	int x = state.posY();
	List<StateB> states = new LinkedList<StateB>();
	StateB newState1 = new StateB();
	newState1.clone();
	newState1.moveRigth(x, y);
	StateB newState2 = new StateB();
	newState2.clone();
	if (state.balVaciaIsLeft()) {
	    newState2.moveUp(x,y);// muevo arriva
	    StateB newState3 = new StateB();
	    newState3.clone();
	    newState3.moveDown(x, y);
	    states.add(newState1);
	    states.add(newState2);
	    states.add(newState3);
	} else {
	    if (state.balVaciaIsLeftSuperior()) {
		newState2.moveDown(x, y);
		states.add(newState1);
		states.add(newState2);
	    } else {
		newState2.moveUp(x, y);// muevo arriva
		states.add(newState1);
		states.add(newState2);
	    }

	}

	return states;
    }

    @Override
    public boolean isApplicable(StateB state) {
	return state.balVaciaIsLeftInf() || state.balVaciaIsLeftSuperior()
		|| state.balVaciaIsLeft();
    }

}
